package fr.sharpe.app.earthvisualizationproject.model;

import java.util.HashMap;

import fr.sharpe.app.earthvisualizationdatamodel.Data;
import fr.sharpe.app.earthvisualizationdatamodel.Icon;
import fr.sharpe.app.earthvisualizationdatamodel.Line;
import fr.sharpe.app.earthvisualizationdatamodel.MarkerPoint;
import fr.sharpe.app.earthvisualizationdatamodel.Text;

public class SelectedObjectData {

	public static SelectedObjectData objectSelected = null;
	
	private MarkerPoint marker = null;
	private Line line = null;
	private Icon icon = null;
	private Text text = null;
	
	private boolean haveBeenUpdated = false;
	
	public SelectedObjectData()
	{
		
	}
	
	public static SelectedObjectData getInstance()
	{
		if(objectSelected == null)
		{
			objectSelected = new SelectedObjectData();
		}
		return objectSelected;
	}
	
	public Data getData()
	{
		if(marker != null)
		{
			return marker.getData();
		}
		else if(line != null)
		{
			return line.getData();
		}
		else if(icon != null)
		{
			return icon.getData();
		}
		else if(text != null)
		{
			return text.getData();
		}
		else
		{
			return null;
		}
	}
	
	public void updateSelectedObject(HashMap<String , Object> list, Object type)
	{
		System.out.println("Updating selected object");
		if(type.equals(MarkerPoint.class))
		{
			if(list.containsKey(marker.getId()))
			{
				this.setMarker((MarkerPoint) list.get(marker.getId()));
			}
		}
		if(type.equals(Line.class))
		{
			if(list.containsKey(line.getId()))
			{
				this.setLine((Line) list.get(line.getId()));
			}
		}
		if(type.equals(Icon.class))
		{
			if(list.containsKey(icon.getId()))
			{
				this.setIcon((Icon) list.get(icon.getId()));
			}
		}
		if(type.equals(Text.class))
		{
			if(list.containsKey(text.getId()))
			{
				this.setText((Text) list.get(text.getId()));
			}
		}
	}

	public void setMarker(MarkerPoint marker) {
		this.marker = marker;
		this.icon = null;
		this.line = null;
		this.text = null;
		this.setHaveBeenUpdated(true);
	}

	public MarkerPoint getMarker() {
		return marker;
	}

	public Line getLine() {
		return line;
	}

	public void setLine(Line line) {
		this.line = line;
		this.icon = null;
		this.marker = null;
		this.text = null;
		this.setHaveBeenUpdated(true);
	}

	public Icon getIcon() {
		return icon;
	}

	public void setIcon(Icon icon) {
		this.icon = icon;
		this.marker = null;
		this.line = null;
		this.text = null;
		this.setHaveBeenUpdated(true);
	}

	public Text getText() {
		return text;
	}

	public void setText(Text text) {
		this.text = text;
		this.icon = null;
		this.line = null;
		this.marker = null;
		this.setHaveBeenUpdated(true);
	}

	public void setHaveBeenUpdated(boolean haveBeenUpdated) {
		this.haveBeenUpdated = haveBeenUpdated;
	}

	public boolean isHaveBeenUpdated() {
		return haveBeenUpdated;
	}
	
}
